<?php
namespace App\Job\Prize;

use App\Query\ConfigQuery;
use App\Query\UserQuery;
use App\Repository\UserRepository;

class WalletRed
{
    public function run()
    {
        // 获取配置
        $config = ConfigQuery::get();
        
        // 获取用户
        $users = UserQuery::moneyWalletTime()->get();
        
        // 仓库
        $repository = UserRepository::make();
        
        // 循环
        foreach($users as $user)
        {
            $repository->model($user);
            
            // 算出分红多少钱
            $money = ConfigQuery::bi($config, 'wallet_red', $user->money_wallet);
            
            // 分红
            $repository->addMoney('money_wallet', $money, '每日钱包分红', 'wallet_red');
            
            // 更新时间
            $repository->setMoneyWalletTime();
        }
    }
}